package com.ruoyi.web.controller.module;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.Feedback;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.module.IFeedbackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 意见反馈Controller
 *
 * @author ruoyi
 * @date 2021-08-24
 */
@Validated
@Api(value = "意见反馈控制器", tags = {"意见反馈管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/feedback")
public class FeedbackController extends BaseController {

    private final IFeedbackService feedbackService;

    /**
     * 查询意见反馈列表
     */
    @ApiOperation("查询意见反馈列表")
    @PreAuthorize("@ss.hasPermi('module:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo<Feedback> list(@Validated Feedback feedback) {
        return PageUtils.buildDataInfo(feedbackService.page(PageUtils.buildPage()));
    }

    /**
     * 导出意见反馈列表
     */
    @ApiOperation("导出意见反馈列表")
    @PreAuthorize("@ss.hasPermi('module:feedback:export')")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<Feedback> export(@Validated Feedback feedback) {
        List<Feedback> list = feedbackService.list();
        ExcelUtil<Feedback> util = new ExcelUtil<Feedback>(Feedback.class);
        return util.exportExcel(list, "意见反馈");
    }

    /**
     * 获取意见反馈详细信息
     */
    @ApiOperation("获取意见反馈详细信息")
    @PreAuthorize("@ss.hasPermi('module:feedback:query')")
    @GetMapping("/{id}")
    public AjaxResult<Feedback> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        Feedback feedback = feedbackService.getById(id);
        return AjaxResult.success(feedback);
    }

    /**
     * 新增意见反馈
     */
    @ApiOperation("新增意见反馈")
    @PreAuthorize("@ss.hasPermi('module:feedback:add')")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody Feedback feedback) {
        return toAjax(feedbackService.save(feedback) ? 1 : 0);
    }

    /**
     * 修改意见反馈
     */
    @ApiOperation("修改意见反馈")
    @PreAuthorize("@ss.hasPermi('module:feedback:edit')")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody Feedback feedback) {
        return toAjax(feedbackService.updateById(feedback) ? 1 : 0);
    }

    /**
     * 删除意见反馈
     */
    @ApiOperation("删除意见反馈")
    @PreAuthorize("@ss.hasPermi('module:feedback:remove')")
    @Log(title = "意见反馈" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(feedbackService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
